<template>
	<view>
		<!-- 搜索组件 -->
		<view class="search-box">
			<my-search @myGoSearch='goSearch'></my-search>	
		</view>
		
		<!-- 轮播图 -->
		<swiper class="swiper" :indicator-dots="true" :autoplay="true" :interval="3000" :circular="true" :duration="1000">
			<swiper-item class="swiper-item"  v-for="(item,index) in swiperList" :key="index">
				<navigator :url="'/subpkg/goods_detail/goods_detail?goods_id='+item.goods_id">
				<view class="swiper-item">
					<image :src="item.image_src" mode=""></image>
				</view>
				</navigator>
			</swiper-item>
		</swiper>
		<!-- 分类导航 -->
		<view class="nav-list">
			<view class="nav-list-item" v-for="(item,index) in navList" :key="index" @click="checkNav(item)">
				<image class="nav-img" :src="item.image_src" mode=""></image>
				<!-- <text>{{item.name}}</text> -->
			</view>
		</view>
		<!-- 楼层区域 -->
		<view class="floor-list">
			<view class="floor-item" v-for="(item,index) in floorList" :key="index">
				<image class="floor-title" :src="item.floor_title.image_src" mode=""></image>
				<!-- 楼层图片区域 -->
				<view class="floor-img-box">
					<!-- 左侧大图片的盒子 -->
					<navigator :url="item.product_list[0].url" class="left-img-box">
						<image :src="item.product_list[0].image_src" :style="{width:
						item.product_list[0].image_width + 'rpx'}" mode="widthFix"></image>
					</navigator>
					<!-- 右侧 4 个小图片的盒子 -->
					<view class="right-img-box">
						<navigator :url="item2.url" class="right-img-item" v-for="(item2, index2) in item.product_list"
						:key="index2" v-if="index2 !== 0">
							<image :src="item2.image_src" mode="widthFix" :style="{width:
							item2.image_width + 'rpx'}"></image>
						</navigator>
					</view>
				</view>
				
			</view>
		</view>
		
	</view>
</template>

<script>
	import badgeMix from '@/mixins/tabbar-badge.js'
	export default {
		mixins:[badgeMix],
		data() {
			return {
				swiperList: [], //存放轮播图数据
				navList:[],//分类导航数据列表
				floorList:[],//楼层数据
			};
		},
		onLoad() {
			this.getSwiperList()
			this.getNavList()
			this.getFloorList()
		},

		methods: {
			goSearch(e){
				console.log('父组件',e)
				uni.navigateTo({
					url:'/subpkg/search/search'
				})
			},
			getFloorList(){
				uni.$http.get('/api/public/v1/home/floordata').then( res => {
					// 成功的回调
					let {data} = res
					console.log('getFloorList',res)
					if(data.meta.status === 200){
						this.floorList = data.message.map(item => {
							item.product_list.forEach(item2 => {
								item2.url = '/subpkg/goods_list/goods_list?' + item2.navigator_url.split('?')[1]
							})
							return item
						})
					}
				},err => {
					// 失败的回调
					this.$showMsg()
				})
			},
			checkNav(item){
				if(item.name == '分类'){
					uni.switchTab({
						url:'/pages/cate/cate'
					})
				}
			},
			getNavList(){
				uni.$http.get('/api/public/v1/home/catitems').then(res => {
					// console.log("getNavList",res)
					if(res.data.meta.status === 200){
						this.navList = res.data.message
					}
				}).catch(err => {
					uni.$showMsg()
				})
			},
			async getSwiperList() {
				let {data} = await uni.$http.get('/api/public/v1/home/swiperdata')
				// console.log("getSwiperList", data)
				if(data.meta.status !== 200){
					return uni.$showMsg()
				}
				this.swiperList = data.message
				uni.$showMsg('数据请求成功！')
			}
		}
	}
</script>

<style lang="scss">
	// 轮播图样式
.swiper {
		height: 300rpx;
	}
	.swiper-item {
		display: block;
		height: 300rpx;
		line-height: 300rpx;
		text-align: center;
		
		navigator,image{
			width: 100%;
			height: 100%;
		}
	}
	// 分类导航样式
	.nav-list{
		display: flex;
		justify-content: space-around;
		margin: 15px 0;
		.nav-list-item{
			.nav-img{
				width: 128rpx;
				height: 140rpx;
			}
		}
		
	}
	// 楼层样式
			.floor-title{
				height: 60rpx;
				width: 100%;
				display: flex;
			}
			.right-img-box {
			display: flex;
			flex-wrap: wrap;
			justify-content: space-around;
			}
			.floor-img-box {
			display: flex;
			padding-left: 10rpx;
			}
.search-box{
	position: sticky;
	z-index: 999;
	top: 0;
}
			
	
</style>
